package leetCode.solution;

public class Solution151 {
	public String reverseWords(String s) {
		if(s==null || s.length()<=1 || !s.trim().contains(" ")) {
			return s;
		}
		StringBuffer sb = new StringBuffer();
		String[] arr = s.split(" ");
		for(int i = arr.length-1;i>=0;i--) {
			if("".equals(arr[i])) continue;
			sb.append(arr[i]+ " ");
		}
		return sb.toString().trim();
	}
	
	
	public static void main(String[] args) {
		System.out.println(new Solution151().reverseWords(" aa  bbb cc   "));
	}
}